package com.example.huffman;

import java.util.List;

/**
 * Created by Administrator on 2017/9/23 0023.
 */

public class CodeTable {
    char[] code;
    ChildNode childNode;

    public CodeTable(List<Character> characters, int i, ChildNode childNode) {
        this(createCodes(characters, i), childNode);
    }

    public CodeTable(char[] code, ChildNode childNode) {
        this.code = code;
        this.childNode = childNode;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(childNode.c).append(":").append(code);
        return stringBuilder.toString();
    }

    static char[] createCodes(List<Character> characters, int end) {
        char[] chars = new char[end];
        for (int i = 0; i < end; ++i) {
            chars[i] = characters.get(i);
        }
        return chars;
    }

}
